// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
// import ElementUI from "element-ui"
import "element-ui/lib/theme-chalk/index.css"
import App from './App'
import router from './router'
import axios from 'axios';
import Vuex from 'vuex';
import  fastClick from 'fastclick'  //引入解决 点击延时插件
Vue.use(Vuex);
// Vue.use($);
Vue.prototype.$http = axios;
Vue.config.productionTip = false;
fastClick.attach(document.body);  //点击延时插件

import {
  Select,
  Cascader,
  Option,
  Pagination,
  Tabs,
  CheckboxGroup,
  Checkbox,
  Upload,
  Form,
  FormItem,
  dialog,
  DatePicker,
  RadioGroup,
  radio,
  Tree,
  Button,
  TabPane,
  input,
  Switch,
  TimePicker,
  TimeSelect,
  Radio,
  Carousel,
  CarouselItem,
  MessageBox,
  Message,

} from 'element-ui';

Vue.config.productionTip = false;
Vue.use(RadioGroup);
Vue.use(radio);
Vue.use(Select);
Vue.use(DatePicker);
Vue.use(input);
Vue.use(Pagination);
Vue.use(dialog);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Cascader);
Vue.use(Checkbox);
Vue.use(Upload);
Vue.use(Option);
Vue.use(CheckboxGroup);
Vue.use(Tree);
Vue.use(Button);
Vue.use(Tabs);
Vue.use(TabPane);
Vue.use(Switch);
Vue.use(TimePicker);
Vue.use(TimeSelect,);
Vue.use( Radio,);
Vue.use(Carousel);
Vue.use(CarouselItem)
Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.prototype.$prompt = MessageBox.prompt;
Vue.prototype.$message = Message;
/* eslint-disable no-new */
axios.defaults.baseURL = 'http://men.wuyoufang.com/api';
axios.interceptors.request.use(
  config => {
    // 这里写死一个token，你需要在这里取到你设置好的token的值
    const token = localStorage.token;
    // console.log(token);
    if (token) {
      // 这里将token设置到headers中，header的key是Authorization，这个key值根据你的需要进行修改即可
      config.headers.token = token;
    }else {
      router.push({name: 'Login'});
    }
    return config
  },
  error => {
    return Promise.reject(error)
  });


// 响应拦截（配置请求回来的信息）
axios.interceptors.response.use(function (response) {
  console.log(response.data);
  try{
    if (response.data.error_code === '20001') {
      router.push({name: 'Login'});
    }
  }catch (e) {

  }

  // 处理响应数据
  return response;
}, function (error) {
  // 处理响应失败
  // router.push({name: 'Login'});
  return Promise.reject(error);
});
const store = new Vuex.Store({
  state: {
    messageString: '',
    warnmessageString: '',
    menus: [],
    FQid: 0,//分区ID
    LDid: 0,//分区的ID
    DYid: 0,//单元
    LCid: 0,//楼层
    FJid: 0,//房间
    KHid:0,//客户ID
    areaId:0,//片区ID
  },
  getters: {

  },
  mutations: {}
});

new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
});
